<template>
  <el-dialog :modelValue="visiable" title="修改" width="500" @close="$emit('close')">
    <div class="dialog-comp">
      <el-form label-width="100px" :inline="false">
        <el-form-item label="名称">
          <el-input v-model="comp.name"></el-input>
        </el-form-item>
        <el-form-item label="简称">
          <el-input v-model="comp.shortName"></el-input>
        </el-form-item>
        <el-form-item label="法人">
          <el-input v-model="comp.fr"></el-input>
        </el-form-item>
        <el-form-item label="实际负责人">
          <el-input v-model="comp.sjfzr"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="updateComp">修改</el-button>
          <el-button @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>
</template>

<script lang="ts" setup>
import useComp from '@renderer/composables/useComp'
import { ElMessage } from 'element-plus'

const props = defineProps(['visiable', 'comp'])
const emit = defineEmits(['close'])
const { update } = useComp()

const updateComp = async () => {
  await update({
    id: props.comp.id,
    name: props.comp.name,
    shortName: props.comp.shortName,
    fr: props.comp.fr,
    sjfzr: props.comp.sjfzr
  })
  ElMessage({
    type: 'success',
    message: '修改成功'
  })
  emit('close')
}
const cancel = () => {
  emit('close')
}
</script>

<style lang="scss" scoped>
.dialog-comp {
  @apply mt-5;
}
</style>
